package android.lollapalooza;

import android.app.Activity;
import android.os.Bundle;
import android.widget.ImageView;
import android.widget.TextView;
import entities.Band;
import entities.Event;
import entities.Venue;
import service.LollaService;
import service.LollaServiceImpl;

import java.util.List;

public class EventView extends Activity {

	private LollaService mService;
	private TextView mName, mDateTime, mVenue, mBands;
	private ImageView mPhotoLarge;

	@Override
	public void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);
		setContentView(R.layout.eventview);
		mService = new LollaServiceImpl(
				getApplicationContext());

		mName = (TextView) this.findViewById(R.id.name);
		mDateTime = (TextView) this.findViewById(R.id.startEndDateTime);
		mVenue = (TextView) this.findViewById(R.id.venue);
		mBands = (TextView) this.findViewById(R.id.bands);
		mPhotoLarge = (ImageView) this.findViewById(R.id.photoThumbLarge);

		Bundle extras = getIntent().getExtras();
		String name = extras.getString("NAME");
		mName.setText(name);

		Event event = (Event) mService.getByName(name, Event.class);

		String startTime = event.getStartTime();
		String endTime = event.getEndTime();
		String dateTime;
		if (startTime != null && endTime != null) {
			dateTime = (new StringBuilder().append(startTime).append(" - ")
					.append(endTime)).toString();
			mDateTime.setText(dateTime);

		} else {
			dateTime = event.getDate();
			if (dateTime != null) {
				mDateTime.setText(dateTime);
			}
		}

		Venue venue = mService.getVenueByEvent(event);
		if (venue != null) {
			mVenue.setText(venue.getTitle());
		}

		List<Band> bands = mService.getBandsByEvent(event);
		if (bands != null) {
			for (Band band : bands) {
				mBands.append(band.getTitle() + "\n");
			}
		}

		// String photo = Jsoup.parse(event.getPhotoThumbSmall()).text();
		// mPhotoLarge.setText(photoSmall);

	}
}
